<?php

namespace App\Http\Controllers\Customer\Api;

use App\Facades\DeviceService;
use App\Facades\UserService;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class DeviceController extends Controller
{
	public function bind(Request $request)
	{
		$rules = [
				'device_code' => 'required|exists:devices,code',
			];
		$this->validate($request, $rules);
		
		DeviceService::bind(strtolower($request->device_code), $request->type);
		return formatJsonResponse();
	}

    public function control(Request $request)
    {
        $rules = [
            'command' => 'required',
        ];
        $this->validate($request, $rules);
        
        $device = DeviceService::getDeviceByDeviceType($request->type);
        DeviceService::control($request->command, $request->num, $device->code);
        return formatJsonResponse();
    } 

	public function unbind(Request $request)
	{
		$rules = [
				'device_code' => 'required',
			];
		$this->validate($request, $rules);
		
		DeviceService::unbindByDeviceCode($request->device_code);
		return formatJsonResponse();
	}


}
